package cz.muni.fi.pv112.cranesimulator.models.crane.parts;

import cz.muni.fi.pv112.cranesimulator.models.OBJModel;
import static java.lang.Math.abs;

/**
 *
 * @author Michal Ďuriš
 */
public class LiftingRider extends OBJModel {

    private float shift = 0.0f;
    private float shiftStep = 1.0f;

    private static final float MAX_SHIFT_LENGTH = 210.0f;

    public LiftingRider() {
        super();

        path = "/cz/muni/fi/pv112/cranesimulator/resources/models/crane/parts/lifting rider.obj";
    }

    public float getShift() {
        return shift;
    }

    public void setShift(float shift) {
        this.shift = shift;
    }

    public float getShiftStep() {
        return shiftStep;
    }

    public void setShiftStep(float shiftStep) {
        this.shiftStep = shiftStep;
    }

    public float increaseShift() {
        if (shift == MAX_SHIFT_LENGTH) {
            return 0.0f;
        }

        float appliedShift = shiftStep;

        if ((shift + shiftStep) > MAX_SHIFT_LENGTH) {
            appliedShift = MAX_SHIFT_LENGTH - shift;
        }

        shift += appliedShift;

        return appliedShift;
    }

    public float decreaseShift() {
        if (shift == 0.0f) {
            return 0.0f;
        }

        float appliedShift = shiftStep;

        if ((shift - shiftStep) < 0.0f) {
            appliedShift = abs(0.0f - shift);
        }

        shift -= appliedShift;

        return appliedShift;
    }

}
